import 'package:json2dart_safe/json2dart.dart';
import 'dart:convert';

/// 自定义响应对象
class ResponseEntity {
  /// 响应码
  int? code;

  /// 响应消息
  String? msg;

  /// 响应时间
  String? timestamp;

  /// 响应数据
  dynamic data;

  ResponseEntity({
    this.code,
    this.msg,
    this.timestamp,
    this.data,
  });

  Map<String, dynamic> toJson() => {
        'code': code,
        'msg': msg,
        'timestamp': timestamp,
        'data': data,
      };

  ResponseEntity.fromJson(Map json) {
    code = json.asInt('code');
    msg = json.asString('msg');
    timestamp = json.asString('timestamp');
    data = json['data'];
  }

  @override
  String toString() => jsonEncode(toJson());
}
